﻿using GBT.Business.GBT_Manage;
using GBT.Entity;
using GBT.Entity.GBT_Manage;
using GBT.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace GBT.AmoebaManage.Controllers.GBT_Manage
{
    [Route("/GBT_Manage/[controller]/[action]")]
    public class GBT_ServiceRequestController : BaseApiController
    {
        #region DI

        public GBT_ServiceRequestController(IGBT_ServiceRequestBusiness gBT_ServiceRequestBus)
        {
            _gBT_ServiceRequestBus = gBT_ServiceRequestBus;
        }

        IGBT_ServiceRequestBusiness _gBT_ServiceRequestBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<GBT_ServiceRequestDTO>> GetDataList(PageInput<GBT_ServiceRequestConditionDTO> input)
        {
            return await _gBT_ServiceRequestBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<GBT_ServiceRequest> GetTheData(IdInputDTO input)
        {
            return await _gBT_ServiceRequestBus.GetTheDataAsync(input.id);
        }

        [HttpPost]
        public async Task<List<GBT_ServiceRequestUserDTO>> GetServiceRequestUserList(IdInputDTO input)
        {
            return await _gBT_ServiceRequestBus.GetServiceRequestUserListAsync(input.departmentIds, input.RequestId, _op?.UserId);
        }

        [HttpPost]
        public async Task<List<GBT_ServiceDeliveryUserDTO>> GetServiceDeliveryUserList(IdInputDTO input)
        {
            return await _gBT_ServiceRequestBus.GetServiceDeliveryUserListAsync(input.departmentIds, input.RequestId, _op?.UserId);
        }

        [HttpPost]
        public async Task<PageResult<GBT_ServiceItemsDTO>> GetServiceItemList(PageInput<GBT_Base_ServiceItemConditionDTO> input)
        {
            input.Search.UserId = _op?.UserId;
            return await _gBT_ServiceRequestBus.GetServiceItemsListAsync(input);
        }

        [HttpPost]
        public async Task<List<GBT_ApprovalDTO>> GetApprovalList(IdInputDTO input)
        {
            return await _gBT_ServiceRequestBus.GetApprovalListAsync(input.departmentIds, input.RequestId, input.State);
        }

        [HttpPost]
        public async Task<List<GBT_ApprovalDTO>> GetApprovalHistoryList(IdInputDTO input)
        {
            return await _gBT_ServiceRequestBus.GetApprovalHistoryAsync(input.id);
        }
        #endregion

        #region 提交
        [HttpPost]
        public async Task Evaluate(GBT_ServiceRequestDTO data)
        {
            await _gBT_ServiceRequestBus.EvaluateAsync(data, _op?.UserId);
        }

        [HttpPost]
        public async Task SaveData(GBT_ServiceRequestDTO data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                await _gBT_ServiceRequestBus.AddDataAsync(data);
            }
            else
            {
                await _gBT_ServiceRequestBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task SaveAllData(GBT_ServiceRequestDTO data)
        {
            await _gBT_ServiceRequestBus.SaveDataAsync(data, _op?.UserId);
        }
        
        [HttpPost]
        public async Task Approval(GBT_ServiceRequestDTO data)
        {
            await _gBT_ServiceRequestBus.ApprovalAsync(data, _op?.UserId);
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _gBT_ServiceRequestBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}